package com.haidechizi.longpolling.client.web;

import com.haidechizi.longpolling.client.adapter.LongPollingAdapter;
import com.haidechizi.longpolling.client.entity.LongPollingDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author wangdejun
 * @create 2021/2/24 11:12
 */
@RestController
@RequestMapping("longPolling")
public class LongPollingController {

    @Autowired
    private LongPollingAdapter longPollingAdapter;

    @PostMapping("listen")
    public void listen(@Validated @RequestBody LongPollingDto longPollingDto, HttpServletRequest request, HttpServletResponse response) {
        longPollingAdapter.doLongPolling(longPollingDto, request, response);
    }
}
